package it.unibo.iss.contact.domoticaContact;

import android.util.Log;
import it.unibo.is.interfaces.IMessage;
import it.unibo.is.interfaces.platforms.IAcquireOneReply;

public class UsrcmdContact extends UsrcmdContactSupport {
	
	private boolean stopThread; 
	private static final String TAGFORLOG = "Usrcmd";
	
	public UsrcmdContact() throws Exception {
		super();
		stopThread = false;
	}

	public void setStopThread(boolean stopThread) {
		this.stopThread = stopThread;
	}

	@Override
	public void doJob() throws Exception {
//		while(!stopThread);
//		Thread.sleep(60000);
	}
	
	public String demandListED() throws Exception {
//		Log.v(TAGFORLOG, "Demanding listed to edController...");
		IAcquireOneReply reply = hl_usrcmdContact_demand_listEd_edController("listed");
//		Log.v(TAGFORLOG, "Receiving listed from edController...");
		String listed = reply.acquireReply().msgContent();
//		Log.v(TAGFORLOG, "listed received");

		return listed;
	}
	
	public static final int SUCCESS = 0;
	public static final int CONSUMPTION_HIGH = -1;
	public static final int FAIL = -2;
	
	public int demandPowerOn(String edName) throws Exception {
		IAcquireOneReply reply = hl_usrcmdContact_demand_powerOn_edController(edName);
		String msg = reply.acquireReply().msgContent();
		if(msg.equals("success"))
			return SUCCESS;
		else if(msg.equals("consumption too high"))
			return CONSUMPTION_HIGH;
		else
			return FAIL;
		
	}
	
	public boolean demandPowerOff(String edName) throws Exception {
		IAcquireOneReply reply = hl_usrcmdContact_demand_powerOff_edController(edName);
		return reply.acquireReply().msgContent().equals("success");		
	}
	
	public String waitForListEdSuperflui() throws Exception {
		IMessage mm = hl_usrcmdContact_serve_listEdSuperflui();
		return mm.msgContent();
	}
	
	public void forwardAbortPowerOffSuperflui() throws Exception {
		hl_usrcmdContact_forward_abortPowerOn_edController("abort poweron");
	}

}
